﻿using System;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using AnyOffice.Components;
using AnyOffice.DAL;
using Webdiver;

namespace AnyOffice.general.rms.roll_file
{
    public partial class index1 : ModulePage
    {
        public void ChangePage(object src, PageChangedEventArgs e)
        {
            this.AspNetPager1.CurrentPageIndex = e.NewPageIndex;
            this.BindData();
        }
        public string GetCodeName(string codeId, string codeType)
        {
            if (codeType == "Secret")
            {
                return new RmsCodeDao().GetCodeName(base.Conn, codeId, RmsCodeDao.CodeType.Secret);
            }
            if (codeType == "Urgency")
            {
                return new RmsCodeDao().GetCodeName(base.Conn, codeId, RmsCodeDao.CodeType.Urgency);
            }
            return string.Empty;
        }
        public string GetRollName(int rollId)
        {
            return new RmsRollDao().GetRollName(base.Conn, rollId);
        }
        private void BindData()
        {
            DataTable table = new RmsFileDao().SelectPaged(base.Conn, this.AspNetPager1.PageSize, this.AspNetPager1.CurrentPageIndex, false);
            this.ViewState["CurrentRowNums"] = table.Rows.Count;
            this.ViewState["CurrentPage"] = this.AspNetPager1.CurrentPageIndex.ToString();
            this.rptRmsFile.DataSource = table;
            this.rptRmsFile.DataBind();
            this.litNavCount.Text = "<span class=\"small1\">共&nbsp;<span class=\"big4\">" + this.AspNetPager1.RecordCount.ToString() + "</span>&nbsp;条";
            this.litNavPager.Text = "<span class=\"small1\">当前为第" + this.AspNetPager1.CurrentPageIndex.ToString() + "页，共" + this.AspNetPager1.PageCount.ToString() + "页，每页最多" + this.AspNetPager1.PageSize.ToString() + "条</span>";
        }
 


        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.Page.IsPostBack)
            {
                DataTable table = new RmsFileDao().SelectPaged(base.Conn, this.AspNetPager1.PageSize, this.AspNetPager1.CurrentPageIndex, true);
                if (int.Parse(table.Rows[0][0].ToString()) == 0)
                {
                    this.litNavCount.Visible = false;
                    this.litNavPager.Visible = false;
                    this.pnlMain.Visible = false;
                    this.litMessage.Text = base.ShowMessage("无文件");
                }
                else
                {
                    this.AspNetPager1.RecordCount = int.Parse(table.Rows[0][0].ToString());
                    this.BindData();
                }
                this.sltRollId.DataSource = new RmsRollDao().SelectOpen(base.Conn);
                this.sltRollId.DataBind();
                this.sltRollId.Items.Insert(0, new ListItem("请选择案卷", ""));
                this.btnChangeRoll.Attributes.Add("onclick", "return change_roll()");
                this.btnDelete.Attributes.Add("onclick", "return buck_delete_roll();");
            }
            if (this.Page.IsPostBack)
            {
                RmsFileDao dao2 = new RmsFileDao();
                foreach (RepeaterItem item in this.rptRmsFile.Items)
                {
                    HtmlInputCheckBox box = (HtmlInputCheckBox)item.FindControl("FileId");
                    if ((box != null) && box.Checked)
                    {
                        if (this.hidAction.Value == "ChangeRoll")
                        {
                            dao2.ChangeRoll(base.Conn, int.Parse(box.Value), Convert.ToInt32(this.sltRollId.Value));
                        }
                        else if (this.hidAction.Value == "DeleteFile")
                        {
                            dao2.Delete(base.Conn, int.Parse(box.Value), base.User.Identity.Name);
                        }
                    }
                }
                base.CloseConn();
                Response.Redirect("index1.aspx?page=" + this.ViewState["CurrentPage"].ToString());
            }


        }
    }
}
